package com.yoda.youdianda.vo;

import com.yoda.youdianda.domain.SysMenu;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.text.SimpleDateFormat;
import java.util.Objects;

/**
 * @author shawn
 * @date 2022年 11月 13日 9:17
 * 单个菜单vo
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MenuVo {
    private Integer id;
    private Integer pid;
    private String path;
    private String component;
    private String title;
    private String icon;
    private Integer is_show;
    private Integer is_cache;
    private Integer is_link;
    private String create_date;
    private String update_date;
    private String redirect;
    private Integer del_flag;
    private Integer type;
    private Integer sort; //0-10
    private String mark;
    private String default_data;

    public static MenuVo init(SysMenu menu, SimpleDateFormat format) {
        MenuVo vo = new MenuVo();
        BeanUtils.copyProperties(menu, vo);
        vo.setIs_show(menu.getIsShow());
        vo.setIs_cache(menu.getIsCache());
        vo.setIs_link(menu.getIsLink());
        vo.setDefault_data(menu.getDefaultData());
        vo.setCreate_date(format.format(menu.getCreateDate()));
        if (!Objects.isNull(menu.getUpdateDate())) {
            vo.setUpdate_date(format.format(menu.getUpdateDate()));
        }
        return vo;
    }
}
